package com.sunyard.authorization;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@SpringBootApplication(scanBasePackages = {"com.sunyard.authorization", "com.sunyard.config",
        "com.sunyard.redisUtil"})
//@EnableZuulProxy
@RestController
@EnableSwagger2
@MapperScan("com.sunyard.dal.mapper")
public class AuthorizationApplication {

    @RequestMapping("/home")
    public String home() {
        return "Hello World";
    }

    public static void main(String[] args) {
        SpringApplication.run(AuthorizationApplication.class, args);
    }


    @Component
    @Primary
    class DocumentationConfig implements SwaggerResourcesProvider {
        public List<SwaggerResource> get() {
            List resources = new ArrayList();
            resources.add(swaggerResource("authorization", "/v2/api-docs", "1.0"));
            return resources;
        }

        private SwaggerResource swaggerResource(String name, String location, String version) {
            SwaggerResource swaggerResource = new SwaggerResource();
            swaggerResource.setName(name);
            swaggerResource.setLocation(location);
            swaggerResource.setSwaggerVersion(version);
            return swaggerResource;
        }
    }
}
